<template>
  <div class="results">
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <van-cell v-for="item in list" :key="item.art_id" :title="item.title" />
      </van-list>
    </van-pull-refresh>
  </div>
</template>

<script>
import { getSearchData } from '@/api/homepage/nav.js'
export default {
  data () {
    return {
      list: [],
      loading: false,
      finished: false,
      refreshing: false,
      page: 1,
      per_page: 10
    }
  },
  props: ['resultData'],
  mounted () {},
  methods: {
    async onLoad () {
      try {
        const params = {
          page: this.page,
          per_page: this.per_page,
          q: this.resultData
        }
        const { data: { data: { results: res } } } = await getSearchData(params)
        this.list.push(...res)
        this.page++
        if (res.lenght === 0) {
          this.finished = true
          console.log(122)
        }
        this.loading = false
      } catch (error) {
        console.log(error)
        this.loading = true
      }
    },
    onRefresh () {
      // 清空列表数据
      this.finished = false
      // 重新加载数据
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      this.onLoad()
    }
  },
  watch: {}
}
</script>

<style lang="scss" scoped>
</style>
